package svc

import (
	"github.com/go-redis/redis/v8"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
	"hzjt-oam/rpc/sys/internal/config"
	"hzjt-oam/rpc/sys/model"
)

type ServiceContext struct {
	Config        config.Config
	UserModel     model.SysUserModel
	RoleModel     model.SysRoleModel
	DeptModel     model.SysDeptModel
	RoleDeptModel model.SysRoleDeptModel
	RDB           *redis.Client
	Mail          config.Config
}

func NewServiceContext(c config.Config) *ServiceContext {
	sqlConn := sqlx.NewMysql(c.Mysql.Datasource)
	return &ServiceContext{
		Config:        c,
		RDB:           model.InitRedis(c),
		UserModel:     model.NewSysUserModel(sqlConn),
		RoleModel:     model.NewSysRoleModel(sqlConn),
		DeptModel:     model.NewSysDeptModel(sqlConn),
		RoleDeptModel: model.NewSysRoleDeptModel(sqlConn),
	}
}
